/**
 * Created by Administrator on 2017/8/1.
 */
// 禁用ctrl+ + 和ctrl+ - 缩放网页
$(document).ready(function () {
    // chrome 浏览器直接加上下面这个样式就行了，但是ff不识别
    $('body').css('zoom', 'reset');
    $(document).keydown(function (event) {
      if ((event.ctrlKey === true || event.metaKey === true)
        && (event.which === 61 || event.which === 107
            || event.which === 173 || event.which === 109
            || event.which === 187  || event.which === 189))
       {
           event.preventDefault();
       }
    });
    $(window).bind('mousewheel DOMMouseScroll', function (event) {
        if (event.ctrlKey === true || event.metaKey) {
           event.preventDefault();
        }
    });
});
// 喊单详情筛选
$(function(){
    $('.selectPZ').click(function(){
        $('.selectPZ_content').toggle();
    })
    $('.jylx').click(function(){
        $(this).css('background','#3b9ce0').siblings().css('background','none').siblings('.selectPZ').css('background','#fff').siblings('.line').css('background','#88888b');
    })
    handanlist(0,0);
})
// 左侧tab切换
$(function(){
    $('.j_navSide > ul > li').click(function(){
        $(this).addClass('active').siblings('li').removeClass('active');
        $('.L_tab_content').siblings('.L_tab_content').hide().eq($(this).index()).show();
    })
})
// 头部下拉效果
$(function(){
    $('#fengxian').hover(function(){
        $('.j_fenxian').show();
    },function(){
        $('.j_fenxian').hide();
    });
    $('#wending').hover(function(){
        $('.j_tuijian').show();
    },function(){
        $('.j_tuijian').hide();
    });
    weekPageFn(1); // 带周分页调用
    $('.header_r').mouseenter(function(){
        $('.j_select').show();//那么就显示div
    }).mouseleave(function(){
        $('.j_select').hide();//就隐藏div
    })
    $('.header_r ').click(function(){
        if($('.j_select').is(':hidden')){//如果当前隐藏
            $('.j_select').show();//那么就显示div
        }else{//否则
            $('.j_select').hide();//就隐藏div
        }
    });
    // tab选项卡
    $(".j_tab span").click(function(){
        $(".j_tab span").eq($(this).index()).addClass("active").siblings().removeClass('active');
        // $(".j_tabcontent").hide().eq($(this).index()).show();
        //另一种方法: $("div").eq($(".tab li").index(this)).addClass("on").siblings().removeClass('on');
        if($(".j_tabcontent").hide().eq($(this).index()).is(':hidden')){//如果当前隐藏
            $(".j_tabcontent").hide().eq($(this).index()).show();
            // 盈亏图
            var week_chart_width ;
            week_chart_width = $('#week_chart').width();
            /*var YK_finalData = [182, 234, 290, 104, 131, 530],
                YK_setProfile = [266, -255, -366, 233, 199],
                YK_setLoss = [333, 444, -855, -266, 577],
                YK_time = ['2017-01-02','2017-01-03','2017-01-04','2017-01-05','2017-01-06'];*/
            YKprofit('week_chart',YK_finalData,YK_setProfile,YK_setLoss,YK_time,week_chart_width);
            // K线图
            // var final_data = [];
            // final_data = dataFn(final,final_data);
            // var data = splitData(final_data);
            var k_width;
            k_width = $('#box_echarts').width();
            /*var data111 = splitData([['2016-10-24',17.93,18.31,17.86,18.42,29.00,0,0.11,-0.05,-0.10],['2016-10-25',18.31,18.13,18.09,18.46,19.00,0,0.06,-0.09,-0.12],['2016-10-26',18.12,17.97,17.95,18.15,14.00,0,0.02,-0.12,-0.13],['2016-10-27',18.06,17.81,17.77,18.06,21.00,0,-0.01,-0.13,-0.13],['2016-10-28',17.8,17.9,17.8,18.05,20.00,0,-0.01,-0.13,-0.13],['2016-10-31',17.87,17.86,17.72,17.96,12.00,0,-0.02,-0.14,-0.13],['2016-11-01',17.87,17.98,17.79,17.99,18.00,0,-0.03,-0.14,-0.12],['2016-11-02',17.86,17.84,17.76,17.94,30.00,0,-0.06,-0.15,-0.12],['2016-11-03',17.83,17.93,17.79,17.97,27.00,0,-0.07,-0.14,-0.11],['2016-11-04',17.9,17.91,17.87,18.0,26.00,0,-0.09,-0.15,-0.10],['2016-11-07',17.91,17.89,17.85,17.93,20.00,0,-0.11,-0.14,-0.09],['2016-11-08',17.92,17.99,17.89,18.06,26.00,0,-0.12,-0.13,-0.07],['2016-11-09',18.0,17.89,17.77,18.08,34.00,0,-0.15,-0.13,-0.06],['2016-11-10',17.95,18.0,17.94,18.11,27.00,0,-0.15,-0.11,-0.03],['2016-11-11',17.95,18.02,17.93,18.08,27.00,0,-0.17,-0.10,-0.01],['2016-11-14',18.0,18.04,17.95,18.25,35.00,0,-0.18,-0.08,0.01],['2016-11-15',18.1,18.18,18.03,18.24,25.00,0,-0.18,-0.06,0.04],['2016-11-16',18.23,18.12,18.05,18.29,23.00,0,-0.21,-0.04,0.06],['2016-11-17',18.11,18.12,18.01,18.14,27.00,0,-0.21,-0.01,0.09],['2016-11-18',18.12,18.1,18.03,18.16,18.00,0,-0.19,0.03,0.12],['2016-11-21',18.08,18.34,18.08,18.68,41.00,0,-0.13,0.08,0.15],['2016-11-22',18.37,18.37,18.28,18.49,52.00,0,-0.09,0.12,0.17],['2016-11-23',18.4,18.84,18.37,18.9,66.00,0,-0.02,0.17,0.18],['2016-11-24',18.77,18.74,18.61,18.97,26.00,0,-0.02,0.17,0.18],['2016-11-25',18.8,18.99,18.66,19.02,40.00,0,-0.01,0.18,0.19],['2016-11-28',19.1,18.65,18.52,19.2,85.00,0,-0.06,0.16,0.19],['2016-11-29',18.65,18.75,18.51,18.76,49.00,0,-0.06,0.17,0.20],['2016-11-30',18.76,18.55,18.47,18.82,39.00,0,-0.08,0.17,0.21],['2016-12-01',18.55,18.49,18.41,18.64,53.00,0,-0.06,0.19,0.22],['2016-12-02',18.53,18.49,18.24,18.54,48.00,0,-0.02,0.21,0.23],['2016-12-05',18.39,18.66,18.34,18.67,50.00,0,0.03,0.25,0.23],['2016-12-06',18.66,18.6,18.57,18.78,31.00,0,0.08,0.26,0.23],['2016-12-07',18.65,18.62,18.58,18.71,12.00,0,0.15,0.29,0.21],['2016-12-08',18.67,18.76,18.62,18.88,26.00,0,0.25,0.32,0.19],['2016-12-09',18.76,19.2,18.75,19.34,62.00,0,0.34,0.33,0.16],['2016-12-12',19.16,19.25,18.9,19.65,79.00,1,0.34,0.28,0.11],['2016-12-13',19.09,18.88,18.81,19.2,24.00,0,0.27,0.20,0.06],['2016-12-14',18.8,18.82,18.8,19.14,32.00,0,0.23,0.13,0.02],['2016-12-15',18.73,18.24,18.2,18.73,36.00,0,0.13,0.05,-0.01],['2016-12-16',18.24,18.18,18.12,18.4,24.00,0,0.10,0.02,-0.03],['2016-12-19',18.15,18.01,17.93,18.18,24.00,0,0.06,-0.02,-0.05],['2016-12-20',17.99,17.79,17.7,17.99,29.00,1,0.02,-0.05,-0.05],['2016-12-21',17.83,17.81,17.77,17.98,30.00,0,0.00,-0.05,-0.06],['2016-12-22',17.85,17.72,17.65,17.85,21.00,0,-0.03,-0.07,-0.06],['2016-12-23',17.77,17.6,17.54,17.77,18.00,0,-0.04,-0.08,-0.05],['2016-12-26',17.56,17.75,17.39,17.77,16.00,0,-0.04,-0.07,-0.05],['2016-12-27',17.73,17.71,17.65,17.82,10.00,0,-0.06,-0.07,-0.04],['2016-12-28',17.72,17.62,17.49,17.77,26.00,0,-0.09,-0.07,-0.03],['2016-12-29',17.6,17.49,17.43,17.62,28.00,0,-0.09,-0.06,-0.02],['2016-12-30',17.53,17.6,17.47,17.61,22.00,0,-0.05,-0.03,-0.01],['2017-01-03',17.6,17.92,17.57,17.98,28.00,1,0.00,0.00,0.00]]);*/
            kxiantu("box_echarts",kfinal_data,k_width);
            // 交易品种
             /*var datatype = [
                {value:335, name:'直接访问'},
                {value:310, name:'邮件营销'},
                {value:234, name:'联盟广告'},
                {value:135, name:'视频广告'},
                {value:1548, name:'搜索引擎'}
            ];;*/
            tradetye('trade_type',datatype)
            // 交易风格
            //交易风格及盈亏点位
            var style_width;
            style_width = $('#style_chart').width();
             var myzdata = $.trim(zdata,'"');
             var lastMyData = myzdata.replace(/&quot;/g,'"');
             var lastMyJsonData = $.parseJSON(lastMyData);
            // 交易风格(长短线)
             var styleDataN = [
                 {
                     value:lastMyJsonData.centerLine,
                     name :'中线'
                 }, //value: 中线单量(图表自动计算百分比)
                 {
                     value:lastMyJsonData.longLine,
                     name :'长线'
                 }, //value: 长线单量(图表自动计算百分比)
                 {
                     value:lastMyJsonData.shortLine,
                     name :'短线'
                 }  //value: 短线单量(图表自动计算百分比)
             ];
            
             var styleDataW = [
                 {
                     value:lastMyJsonData.allCenterLineProfitPoint,
                     name:'中线盈利'
                 },
                 {
                     value:-lastMyJsonData.allCenterLineLossPoint,
                     name:'中线亏损'
                 },
                 {
                     value:lastMyJsonData.allLongLineProfitPoint,
                     name:'长线盈利'
                 },
                 {
                     value:-lastMyJsonData.allLongLineLossPoint,
                     name:'长线亏损'
                 },
                 {
                     value:lastMyJsonData.allShortLineProfitPoint,
                     name:'短线盈利'
                 },
                 {
                     value:-lastMyJsonData.allShortLineLossPoint,
                     name:'短线亏损'
                 }
             ];
             sevendayreport('style_chart',styleDataW,styleDataN,style_width);
            // 交易时间分布
            //交易时间分布
            var L_timeFBchart_w;
            L_timeFBchart_w = $('#L_timeFBchart').width();
            /*var data7day = [
                [200, 170, 740, 544, 200, 220, 210,500,600,300,400],
                ['0:00-2:00','2:00-4:00','4:00-6:00','6:00-8:00','8:00-10:00','10:00-12:00','12:00-14:00','14:00-16:00','16:00-18:00','18:00-20:00','22:00-24:00'],
                [2, 3, 4, 5, 7, 8, 6,3,0,-1,2],
            ];*/
            timeFBreport('L_timeFBchart',data7day,L_timeFBchart_w);
            // 盈损时间分布图
            var L_YSchart_w;
            L_YSchart_w = $('#L_YSchart').width();
//            var dataYS = [
//                [220, 182, 191, 234, 290, 330, 310,600], //总盈利点
//                [-220, -182, -191, -234, -290, -330, -310,-600], //总亏损点
//                [2, 17, -40, 54, 20, -22, 21,50,-60,50], //比例
//                ['0-10','10-20','20-30','30-40','40-50','50-60','60-70','70-80','80-90','90-100','100以上']
//            ];
            YSreport('L_YSchart',dataYS,L_YSchart_w);
            //如果点击的非交易行为页   滚动条隐藏
            if($(this).index() != 1){
                $('#tradeLB_content').getNiceScroll().hide();
            }
        }
    });
    // 收益曲线图
    /*var data = [
        ['2017-01-02','2017-03-03','2017-05-04','2017-05-02','2017-08-01'],
        [8,5,-6,7,2]
    ];*/
    // 日报表
    // var dataday = [
    //     [200, 170, -740, 544, 200, -220, 210,500,-600,-300,-400,-500,800],
    //     ['2017-01-02','2017-01-03','2017-01-04','2017-01-05','2017-01-06','2017-01-07','2017-01-08','2017-01-09','2017-01-10','2017-01-11','2017-01-12','2017-01-13','2017-01-14'],
    //     [2, 3, 4, 5, 7, 8, 6,3,0,-1,2,9,4],
    // ];
    // //周报表
    // dayreport('dayzhou_chart',dataday);
});
//编辑订阅
$(function(){
    $('#j_copyone').click(function(){
        $('.j_compile_copy').show();
    })
    $('#j_X').click(function(){
        $('.j_compile_copy').hide();
    })
})
// 带周的上下分页
var zongarr         = new Array();
function weekPageFn(page,type){ //page:页码 type:1上一页 2下一页
    var finalpoint      = 0;
    if(page != 1 && type != 1){
        finalpoint      = $('#j_tabzhou ul').last().prev().find('li:eq(1)').html().replace('点','');
        zongarr[page-1]  = [finalpoint];
    }
    //上一页 下一页 总计的参数
    if(page != 1 && type == 1){
        finalpoint      = zongarr[page-1][0];
    }else if(page == 1 && type == 2){
        finalpoint      = zongarr[page][0];
    }
    $.ajax({
        type:'get',
        url:weekPage,
        data:{analyst_id:analyst_id,page:page,finalpoint:finalpoint},
        async: true,
        success:function(e){
            var ev = eval('(' + e + ')');
            var html = '';
            var weelpagecount = ev.orderdata.length;
            html += '<ul><li></li><li>总收益</li><li>增长比例</li><li>策略数量</li></ul>';
            for(var i=0;i < weelpagecount;i++){
                html += '<ul><li>第';
                if(page == 1){
                    html += i+1;
                }else{
                    html += ((ev.page-1)*8+(i+1));
                }
                html +='周</li><li class="';
                if(ev.orderdata[i].final_point < 0 ){
                    html += 'green';
                }else{
                    html += 'red';
                }
                html +='">'+ev.orderdata[i].final_point
                     +'点</li><li class="';
                if(ev.orderdata[i].scale < 0 ){
                    html += 'green';
                }else{
                    html += 'red';
                }
                html +='">'+ev.orderdata[i].scale
                     +'%</li><li>'+ev.orderdata[i].num
                     +'单</li></ul>';
            }
            var shengyucount = 8-weelpagecount;
            if(shengyucount > 0) {
                for (var i = 0; i < shengyucount; i++) {
                    html += '<ul><li>第';
                    if (page == 1) {
                        html += weelpagecount + i + 1;
                    } else {
                        html += ((ev.page - 1) * 8 + (weelpagecount + i + 1));
                    }
                    html += '周</li><li>0点</li><li>0%</li><li>0单</li></ul>';
                }
            }
            html+= '<ul> <li>总计</li><li class="';
            if(ev.allFinalPoint < 0 ){
                html += 'green';
            }else{
                html += 'red';
            }
            html+='">'+ev.allFinalPoint+'点</li><li class="';
            if(ev.allScale < 0 ){
                html += 'green';
            }else{
                html += 'red';
            }
            html+='">'+ev.allScale+'%</li><li>'+ev.allOrderNum+'单</li></ul>';
            html+= '<br style="clear: both;"><div class="j_tabpage"><span ';
            if(ev.page != 1){
                html += 'style="background:#00a8ee;" onclick="week(1,'+ev.page+','+ev.totalpage+')"';
            }
            html+='>上一页</span><b>'+ev.page+'</b><span ';
            if(ev.page < ev.totalpage) {
                html += 'style="background:#00a8ee;"  onclick="week(2,' + ev.page + ',' + ev.totalpage + ')"';
            }
            html+='>下一页</span></div>';
            $('#j_tabzhou').html(html);
        }
    })

}
function week(type,page,totalpage){
  if(type == 1 && page > 1){
    page = page - 1;
  }else if(type == 1 && page <= 1){
    page = 1;
  }else if(type == 2 && page < totalpage){
    page = page + 1;
  }else if(type == 2 && page >= totalpage){
      page = totalpage;
  }
  weekPageFn(page,type);
}
// 个人简介查看全部
$(function() {
    var max = 170,
        display = "...显示全部";
    $(".z_content_right_two").on("click", ".ckgd", function() {
        var me = this,
            show = $(me).text() == display,
            attr = show ? "his" : "sub",
            name = show ? "收起" : display;
        $(this).parent().each(function() {
            $(this).html($(this).attr(attr)).append($(me).clone(true).text(name));
        });
    });
    $(".z_box_z").each(function() {
        var me = this,
            html = $(me).html(),
            text = getElementText(me),
            length = text.length,
            sub = text.substr(0, max);
        $(me).attr({
            his: text,
            sub: sub
        });
        if(length > max) {
            $(me).html(sub);
            $(me).append(
                $("<a href='javascript:void(0)' class='ckgd'>".concat(display, "</a>"))
            );
        }
    });
});
// 点击查看全部的函数封装
function getElementText(e) {
    var t = "";
    //如果传入的是元素，则继续遍历其子元素
    //否则假定它是一个数组
    e = e.childNodes || e;
    //遍历所有子节点
    for(var j = 0; j < e.length; j++) {
        //如果不是元素，追加其文本值
        //否则，递归遍历所有元素的子节点
        t += e[j].nodeType != 1 ? e[j].nodeValue : text(e[j].childNodes);
    }
    //返回区配的文本
    return t;
}
// 收益曲线图
function profit(id,data){
    var t = this;
    return new Highcharts.Chart({
        chart: {
            renderTo: id,
            type: "areaspline",
            zoomType: "xy",
            backgroundColor: '#171922'
        },
        title: {
            text : null
        },
        subtitle: {
            text: '点/日期',
            align: 'left',
            verticalAlign: 'bottom'
        },
        colors: ["#ffc766"],
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled:false
        },
        xAxis: {
            gridLineWidth: 0,
            lineColor: "#23272e",
            tickColor: "#23272e",
            gridLineColor: "#23272e",
            categories:data[0],
            tickInterval: Math.ceil(data[0].length / 7),

        },
        yAxis: {
            gridLineWidth: 1,
            lineColor: "#23272e",
            tickColor: "#23272e",
            gridLineColor: "#23272e",
            title: {
                text: null
            }
        },
        tooltip: {
            style: {
                color: "white"
            },
            borderWidth: 1,
            shadow: !1,
            shared: !0,
            backgroundColor: 'rgba(0,0,0)',   // 背景颜色
            borderColor: '#3b9ce0',       // 边框颜色
            formatter : function (){ // 提示框格式化字符串
                var s;
                $.each(this.points ,function(){
                    s = '<b>总收入: ' + this.y+'点'+'</b><br/>';
                });
                s += '<b>截止: '+this.x+'</b>';
                return s;
            }
        },
        plotOptions: {
            areaspline: {
                fillColor: {
                    linearGradient: {
                        x1: 0,
                        y1: 0,
                        x2: 0,
                        y2: 1
                    },
                    stops: [
                        [0, "#3b9ce0"],
                        [1, Highcharts.Color("#3b9ce0").setOpacity(0).get('rgba')]
                    ]
                },
                marker: {
                    radius: 0,
                    fillColor: "white",
                    lineWidth: 1,
                    lineColor: "#ffc766"
                },
                lineWidth: 1,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            },
            series: {
                lineColor: "#3b9ce0"
            }
        },
        series: [{
            name: "盈利点位",
            data: data[1]
        }]
    })
}
// 日报表  柱子: 盈亏点数  时间;  移入:单量 盈亏点数  时间
function dayreport(id,data){
    var mydayChart = echarts.init(document.getElementById(id))
    option = {
        title: {
            subtext : '数量/日期',
            left: '2%',
            bottom: '10%',
            // subtextStyle: { 标题样式
            //     color: 'red'
            // }
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            textStyle: { // 图例字体样式
                fontSize: 12
            },
            formatter: function (params) { // 鼠标悬浮在柱子上显示的提示文本
                var tar = params[0]; // 显示单量,盈亏点数,时间
                return '单量: '+data[2][tar.dataIndex]+'单'+'<br/>'+'盈亏: '+data[0][tar.dataIndex]+'点'+'<br/>'+'日期: '+data[1][tar.dataIndex]+'';
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        yAxis : [
            {
                type : 'value',
                show: false,
                splitLine:{ //去除网格线
                    show: false
                }
                // splitArea : {//保留网格区域
                //     show : true
                // }
            }
        ],
        xAxis : [
            {
                type : 'category',
                show: true, // 显示x轴
                axisTick : { //显示刻度线
                    show: true
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff'
                    },
                    interval: 2 // 隔2天显示一个x轴的刻度
                },
                data : data[1]
            }
        ],
        series : [
            {
                name:'盈亏',
                type:'bar',
                // barWidth : 30,//柱图宽度
                barMaxWidth:30,//柱子最大宽度
                label: {
                    normal: {
                        show: true,
                        position: 'top', //数据显示在柱图顶部
                        textStyle: {
                            color: '#fff'
                        },
                        formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                            return params.data
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: function(params) {
                            var colorList = [
                                '#e94b5d','#89ff29'
                            ];
                            if(params.data < 0) { // 如果数据 < 0, 设置不同颜色
                                return colorList[1];
                            }
                            return colorList[0];
                        },
                        label: {
                            show: true,
                            position: 'top',
                            formatter: '{b}\n{c}'
                        }
                    }
                },
                data:data[0]
            }
        ]
    };
    mydayChart.setOption(option);
    window.onresize = function () {
        mydayChart.resize(); //使第一个图表适应
    }
}
// 盈亏图
function YKprofit(id,YK_finalData,YK_setProfile,YK_setLoss,YK_time,week){

    var myYKChart = echarts.init(document.getElementById(id));
    option = {
        title: {
            text: '',
            subtext: null,
            textStyle: {
                color: '#fff',
                fontSize: 14
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            right: 20,
            data: [{
                name: '最终盈亏',
                // 强制设置图形为长方形。
                icon: 'rect',
                // 设置文本为白色
                textStyle: {
                    color: '#fff'
                }
            },{
                name: '设置止盈',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            },{
                name: '设置止损',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }]
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        yAxis: {
            type: 'value',
            axisTick: {
                show: false
            },
            splitLine:{ //去除网格线
                show: false
            },
            axisLine: { // 取消坐标轴的线
                show: false
            },
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            },
            boundaryGap: [0, 0.01]
        },
        xAxis: {
            type: 'category',
            splitLine:{ //去除网格线
                show: false
            },
            axisLine:{
                lineStyle: {
                    color: '#474b6d'
                }
            },
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            },
            data: YK_time
        },
        series: [
            {
                name: '最终盈亏',
                type: 'bar',
                barMaxWidth: 20,
                label: {
                    normal: {
                        show: true,
                        position: 'top', //数据显示在柱图顶部
                        textStyle: {
                            color: '#fff'
                        },
                        formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                            return params.data
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: function(params){
                            var colorList = [
                                '#f0be36'
                            ];
                            return colorList[0]
                        }
                    }
                },
                data: YK_finalData
            },{
                name: '设置止盈',
                type: 'bar',
                barMaxWidth: 20,
                label: {
                    normal: {
                        show: true,
                        position: 'top', //数据显示在柱图顶部
                        textStyle: {
                            color: '#fff'
                        },
                        formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                            return params.data
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: function(params){
                            var colorList = [
                                '#9c303c'
                            ];
                            return colorList[0]
                        }
                    }
                },
                data: YK_setProfile
            },{
                name: '设置止损',
                type: 'bar',
                barMaxWidth: 20,
                label: {
                    normal: {
                        show: true,
                        position: 'top', //数据显示在柱图顶部
                        textStyle: {
                            color: '#fff'
                        },
                        formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                            return params.data
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: function(params){
                            var colorList = [
                                '#0dff85'
                            ];
                            return colorList[0]
                        }
                    }
                },
                data: YK_setLoss
            }
        ]
    };
    myYKChart.setOption(option);
    myYKChart.resize({
        width: week // tab切换时,设置canvas宽度为父元素的宽度
    });

}
// k线图的数据分割整理
function dataFn(id){
    var idData = [];
    id = id.split(';');
    id.forEach(function(data,index,arr){
        var point_val = data.split(',');
        var parr = [];
        if(point_val[0]){
            point_val.forEach(function (da,num,arr) {
                if(num == 0){
                    parr.push(da);
                }else{
                    parr.push(+da);
                }
            });
            idData.push(parr);
        }
//          console.log(idData);
    });
    return idData;
}
//K线图的数组处理
function splitData(rawData) {
    var datas = [];
    var times = [];
    var vols = [];
    var macds = []; var difs = []; var deas = [];
    for (var i = 0; i < rawData.length; i++) {
        datas.push(rawData[i]);
        times.push(rawData[i].splice(0, 1)[0]);
        vols.push(rawData[i][4]);
        macds.push(rawData[i][6]);
        difs.push(rawData[i][7]);
        deas.push(rawData[i][8]);
    }
    return {
        datas: datas,
        times: times,
        vols: vols,
        macds: macds,
        difs: difs,
        deas: deas
    };
}
//k线图的分段计算
function fenduans(){
    var markLineData = [];
    var idx = 0; var tag = 0; var vols = 0;
    for (var i = 0; i < kfinal_data.times.length; i++) {
        //初始化数据
        if(kfinal_data.datas[i][5] != 0 && tag == 0){
            idx = i; vols = kfinal_data.datas[i][4]; tag = 1;
        }
        if(tag == 1){ vols += kfinal_data.datas[i][4]; }
        if(kfinal_data.datas[i][5] != 0 && tag == 1){
            markLineData.push([{
                xAxis: idx,
                yAxis: kfinal_data.datas[idx][1]>kfinal_data.datas[idx][0]?(kfinal_data.datas[idx][3]).toFixed(2):(kfinal_data.datas[idx][2]).toFixed(2),
                value: vols
            }, {
                xAxis: i,
                yAxis: kfinal_data.datas[i][1]>kfinal_data.datas[i][0]?(kfinal_data.datas[i][3]).toFixed(2):(kfinal_data.datas[i][2]).toFixed(2)
            }]);
            idx = i; vols = kfinal_data.datas[i][4]; tag = 2;
        }

        //更替数据
        if(tag == 2){ vols += kfinal_data.datas[i][4]; }
        if(kfinal_data.datas[i][5] != 0 && tag == 2){
            markLineData.push([{
                xAxis: idx,
                yAxis: kfinal_data.datas[idx][1]>kfinal_data.datas[idx][0]?(kfinal_data.datas[idx][3]).toFixed(2):(kfinal_data.datas[idx][2]).toFixed(2),
                value: (vols/(i-idx+1)).toFixed(2)+' M'
            }, {
                xAxis: i,
                yAxis: kfinal_data.datas[i][1]>kfinal_data.datas[i][0]?(kfinal_data.datas[i][3]).toFixed(2):(kfinal_data.datas[i][2]).toFixed(2)
            }]);
            idx = i; vols = kfinal_data.datas[i][4];
        }
    }
    return markLineData;
}
//MA计算公式
function calculateMA(dayCount) {
    var result = [];
    for (var i = 0, len = kfinal_data.times.length; i < len; i++) {
        if (i < dayCount) {
            result.push('-');
            continue;
        }
        var sum = 0;
        for (var j = 0; j < dayCount; j++) {
            sum += kfinal_data.datas[i - j][1];
        }
        result.push((sum / dayCount).toFixed(2));
    }
    return result;
}
// 散点图表函数封装
function kxiantu(id,data,k_width){
    var myChartB = echarts.init(document.getElementById(id));
    var option = {
        title: {
            text: '',
            left: 0
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'line'
            }
        },
        legend: {
            data: ['KLine', 'MA5']
        },
        grid: [           {
            left: '3%',
            right: '1%',
            height: '30%'
        },{
            left: '3%',
            right: '1%',
            top: '53%',
            height: '14%'
        },{
            left: '3%',
            right: '1%',
            top: '72%',
            height: '17%'
        }],
        xAxis: [{
            type: 'category',
            data: data.times,
            scale: true,
            boundaryGap: false,
            axisLine: { onZero: false },
            splitLine: { show: false },
            splitNumber: 20,
            min: 'dataMin',
            max: 'dataMax',
            axisLabel:{
                textStyle: {
                    color: '#fff'
                }
            }
        },{
            type: 'category',
            gridIndex: 1,
            data: data.times,
            axisLabel: {show: false}
        },{
            type: 'category',
            gridIndex: 2,
            data: data.times,
            axisLabel: {show: false}
        }],
        yAxis: [{
            scale: true,
            splitArea: {
                show: false
            },
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            },
            splitLine: {
                lineStyle: {
                    color: '#22242d'
                }
            }, //网格线颜色
            itemStyle : {
                normal : {
                    lineStyle:{
                        color:'red'
                    }
                }
            }
        },{
            gridIndex: 1,
            splitNumber: 3,
            axisLine: {onZero: false},
            axisTick: {show: false},
            splitLine: {show: false},
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#fff'
                }
            }
        },{
            gridIndex: 2,
            splitNumber: 4,
            axisLine: {onZero: false},
            axisTick: {show: false},
            splitLine: {show: false},
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#fff'
                }
            }
        }],
        dataZoom: [{
            type: 'inside',
            xAxisIndex: [0, 0],
            start: 20,
            end: 100
        },{
            show: true,
            xAxisIndex: [0, 1],
            type: 'slider',
            top: '93%',
            start: 0,
            end: 100
        },{
            show: false,
            xAxisIndex: [0, 2],
            type: 'slider',
            start: 20,
            end: 100
        }],
        series: [{
            name: '总盈K线周期图表(www.eaifx.com)',
            type: 'candlestick',
            data: data.datas,
            itemStyle: {
                normal: {
                    color: '#ef232a',
                    color0: '#14b143',
                    borderColor: '',  //柱子边框颜色
                    borderColor0: ''
                }
            },
            markArea: {
                silent: true,
                itemStyle: {
                    normal: {
                        color: 'rgba(0,0,0,0)'  //背景方块的颜色
                    }
                },
                data: fenduans()
            },
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                label: {
                    normal: {
                        position: 'middle',
                        textStyle:{color:'Blue',fontSize: 15}
                    }
                },
                data: fenduans(),
                symbol: ['circle', 'none']

            }
        }, {
            name: 'MA5',
            type: 'line',
            data: calculateMA(5),
            smooth: true,
            lineStyle: {
                normal: {
                    opacity: 0.5
                }
            }
        },{
            name: '单量',
            type: 'bar',
            xAxisIndex: 1,
            yAxisIndex: 1,
            data: data.vols,
            itemStyle: {
                normal: {
                    color: function(params) {
                        var colorList;
                        if (data.datas[params.dataIndex][1]>data.datas[params.dataIndex][0]) {
                            colorList = '#ef232a';
                        } else {
                            colorList = '#14b143';
                        }
                        return colorList;
                    },
                }
            }
        },{
            name: '单均盈利',
            type: 'bar',
            xAxisIndex: 2,
            yAxisIndex: 2,
            data: data.macds,
            itemStyle: {
                normal: {
                    color: function(params) {
                        var colorList;
                        if (params.data >= 0) {
                            colorList = '#ef232a';
                        } else {
                            colorList = '#14b143';
                        }
                        return colorList;
                    },
                }
            }
        }
        ]
    };
    myChartB.setOption(option);
    myChartB.resize({
        width: k_width
    })
}
// 交易品种
function tradetye(id,datatype){
    var mytradeChart = echarts.init(document.getElementById(id));
    option = {
        title : {
            text: null,
            subtext: '',
            x:'left',
            y:'20'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        toolbox: {
            show : true,
        },
        calculable : true,
        series : [
            {
                name:'',
                type:'pie',
                radius : '50%',
                center: ['50%', '40%'],
                labelLine:{    
                    normal:{    
                        length:1   // 饼形图指示线长度 
                    }    
                },
                label: {
                    normal: {
                        textStyle : {
                            fontWeight : 'blod',
                            fontSize : '9'
                        }
                    }
                },
                data:datatype
            }
        ],
        color: ['#F7A35C','#8FED7D','#434248','#7CB5EC','#8185E9','#F05D7F']
    };
    mytradeChart.setOption(option);
    window.onresize = function () {
        mytradeChart.resize(); //使第一个图表适应
    }
    // 滚动条
//    $(document).ready(function(){
//        $("#tradeLB_content").niceScroll({
//            cursorborder:"",
//            cursorwidth:"10px",
//            cursorcolor:"#08ff8e",
//            railborderradius: '5px',
//            boxzoom:true,
//            cursoropacitymin: 1,
//            background:"#fcfcfc",
//            autohidemode:false //不隐藏滚动条
//        });
//    })
//    $('#tradeLB_content').getNiceScroll().show();
//    $('#tradeLB_content').getNiceScroll().resize();
}
// 交易风格(长短线)
function sevendayreport(id,styleDataW,styleDataN,style_width){
    var mystyleChart = echarts.init(document.getElementById(id))
    var i=0;
    var colors=['#5e98ef','#90ed7d','#e46b79'];
    option = {
        tooltip: { // 提示框组件---鼠标移入,组件位置
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)",
            position: 'right'
        },
        legend: {
            orient: 'vertical',
            x: 'right'
        },
        series: [
            {
                name:'交易风格',
                type:'pie',
                selectedMode: 'single',
                radius: [0, '30%'],
                label: {
                    normal: {
                        position: 'inner'
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                color:['#5e98ef','#90ed7d','#e46b79'],
                data:styleDataN
            },
            {
                name: '',
                type:'pie',
                label: { // 指示线上文本的大小
                    normal: {
                        show:false ,
                        length:20,   // 饼形图指示线长度
                        textStyle : {
                            fontWeight : 'blod',
                            fontSize : '9'
                        }
                    }
                },
                radius: ['40%', '55%'],
                color:['#875eef','#5ebaef','#67eb6a','#56aa49','#eb9968','#f76a57'],
                data:styleDataW
            }
        ]
    };
    mystyleChart.setOption(option);
}
// 交易时间分布  柱子: 这个时间范围内的 总单量  移入: 这个时间段的胜率
function timeFBreport(id,data,L_timeFBchart_w){
    var mytimeFBChart = echarts.init(document.getElementById(id))
    option = {
        title: {
            subtext : null
            // subtextStyle: { 标题样式
            //     color: 'red'
            // }
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            textStyle: { // 图例字体样式
                fontSize: 12
            },
            formatter: function (params) { // 鼠标悬浮在柱子上显示的提示文本
                var tar = params[0]; // 显示单量,盈亏点数,时间
                return '胜率: '+data[2][tar.dataIndex]+'%'+'<br/>'+'时间: '+data[1][tar.dataIndex]+'';
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        yAxis: {
            splitLine:{ //去除网格线
                show: false
            },
            axisLine: { //隐藏Y轴线
                show: false
            },
            axisTick : { //显示刻度线
                show: false
            },
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            }
        },
        xAxis : {
            type : 'category',
            show: true, // 显示x轴
            axisTick : { //显示刻度线
                show: false
            },
            axisLabel: {
                interval: 0, // 隔0天显示一个x轴的刻度
                textStyle: {
                    color: '#fff'
                }
            },
            axisLine:{
                lineStyle: {
                    color: '#474b6d'
                }
            },
            boundaryGap : true,
            data : data[1]
        },
        series : {
            name:'盈亏',
            type:'bar',
            // barWidth : 30,//柱图宽度
            barMaxWidth:30,//柱子最大宽度
            label: {
                normal: {
                    show: true,
                    position: 'top', //数据显示在柱图顶部
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                        return params.data
                    }
                }
            },
            itemStyle: {
                normal: {
                    color: function(params) {
                        var colorList = [
                            '#c43343','#0dff90'
                        ];
                        if(params.data < 0) { // 如果数据 < 0, 设置不同颜色
                            return colorList[1];
                        }
                        return colorList[0];
                    },
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{b}\n{c}'
                    }
                }
            },
            data:data[0]
        }
    };
    mytimeFBChart.setOption(option);
    // window.onresize = function () {
    //     mytimeFBChart.resize(); //使第一个图表适应
    // }
    mytimeFBChart.resize({
        width: L_timeFBchart_w
    });
}
// 点位区间分布图 柱子: 盈利单量+亏损单量  x轴: 收益点  移入: 盈利总盈点 和 亏损总盈点 的比例
function YSreport(id,dataYS,L_YSchart_w){
    var myYSChart = echarts.init(document.getElementById(id))
    option = {
        title: {
            subtext : '单量/点位区间'
            // subtextStyle: { 标题样式
            //     color: 'red'
            // }
        },
        legend: {
            right: 20,
            data: [{
                name: '总盈利单量',
                // 强制设置图形为长方形。
                icon: 'rect',
                // 设置文本为白色
                textStyle: {
                    color: '#fff'
                }
            },{
                name: '总亏损单量',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }]
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            textStyle: { // 图例字体样式
                fontSize: 12
            },
            formatter: function (params) { // 鼠标悬浮在柱子上显示的提示文本
                var tar = params[0]; // 显示单量,盈亏点数,时间
                var tar1 = params[1];
                return '总盈利单量: '+tar.data+''+'<br/>'+'总亏损单量: '+tar1.data+''+'<br/>'+'盈亏单量比: '+dataYS[2][tar.dataIndex];
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        yAxis: {
            splitLine:{ //去除网格线
                show: false
            },
            axisLine: { //隐藏Y轴线
                show: false
            },
            axisTick : { //显示刻度线
                show: false
            },
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            }
        },
        xAxis : {
            type : 'category',
            show: true, // 显示x轴
            axisTick : { //显示刻度线
                show: false
            },
            axisLabel: {
                interval: 0, // 隔0天显示一个x轴的刻度
                textStyle: {
                    color: '#fff'
                }
            },
            axisLine:{
                lineStyle: {
                    color: '#474b6d'
                }
            },
            boundaryGap : true,
            data : ['0-10','10-20','20-30','30-40','40-50','50-60','60-70','70-80','80-90','90-100','100以上']
        },
        series: [{
            name: '总盈利单量',
            type: 'bar',
            barMaxWidth:30,//柱子最大宽度
            label: {
                normal: {
                    show: true,
                    position: 'top', //数据显示在柱图顶部 如果不设置: 鼠标移入的时候,数据会隐藏
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
                       if(params.data <= 0) {
                           return 1
                       }else{
                            return params.data
                       }
                    }
                }
            },
            itemStyle: {
                normal: {
                    color: '#c43343'
                }
            },
            data: dataYS[0]
        }, {
            name: '总亏损单量',
            type: 'bar',
            barMaxWidth:30,//柱子最大宽度
            label: {
                normal: {
                    show: true,
                    position: 'top', //数据显示在柱图顶部 如果不设置: 鼠标移入的时候,数据会隐藏
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function(params) { // 只显示数据中的指定数据在柱形图顶部
//                        if(params.data <= 0) {
//                            return ''
//                        }else{
                            return params.data
//                        }
                    }
                }
            },
            itemStyle: {
                normal: {
                    color: '#0dff90'
                }
            },
            data: dataYS[1]
        }]
    };
    myYSChart.setOption(option);
    myYSChart.resize({
        width: L_YSchart_w
    })
}
//策略详情
function handanlist(type,dealtype,page){ //type 类型  dealtype:交易类型  1：盈利交易 2：亏损交易 page:页数
        var typenamechange =''; //交易种类
        typenamechange = $('#typenamechange').val();
        $.ajax({
            url:listurl,
            type:'get',
            data:{'analyst_id':analyst_id,'type':type,'dealtype':dealtype,'typename':typenamechange,'page':page},
            dataType:'json',
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success:function(data) {
                var str   = '';
                if(data){
                    str += '<div class="j_handanborder"><ul class="j_handanone"><li>单号</li><li style="width:5%;">品种</li><li>方向</li><li style="width:7%;">入场价格</li><li style="width:16%;">入场时间</li><li>平仓价格</li><li style="width:16%;">平仓时间</li><li style="width:7%;">止盈</li> <li style="width:7%;">止损</li><li>最终盈亏</li></ul></div>';
                    $.each(data.arr,function(key,val){  
                        str += '<div><ul><li>'+val.tradeid+'</li><li style="width:5%;">'+val.typename+'</li><li>';
                        if(val.buy_status == 0){
                            str += '买入';
                        }else{
                            str +='卖出';
                        }
                        str += '</li><li  style="width:7%;">'+val.begin_point+'</li><li style="width:16%;"><span>'+UnixToDate(val.begin_time,false,'',1)+'&nbsp;&nbsp;</span><span>'+UnixToDate(val.begin_time,true,'',0)+'</span></li>';
                        str += '<li>'+val.end_point+'</li><li style="width:16%;"><span>'+UnixToDate(val.end_time,false,'',1)+'&nbsp;&nbsp;</span><span>'+UnixToDate(val.end_time,true,'',0)+'</span></li>';
                        str += '<li style="width:7%;">'+val.target_profit_point+'</li><li style="width:7%;">'+val.target_loss_point+'</li><li';
                        if(val.final_point > 0){
                            str += ' style="color:#fb405a"'
                        }else{
                            str += ' style="color:#89ff29"'
                        }
                        str += '>'+((val.final_point+5) ? (val.final_point+5).toFixed(2):0)+'点</li></ul></div>';
                    })
                     

                    if(data.allpage != 0){
                        str  += '<div class="j_handanpage">';
                        if(data.page !=1){
                            str += '<span class="active" onclick="handanlist('+type+','+dealtype+','+(data.page-1)+')">上一页</span>';
                        }else {
                            str += '<span>上一页</span>&nbsp;';
                        }
                        str += '<b>'+data.page+'</b>&nbsp;';
                        if(data.page != data.allpage){
                            str += '<span class="active" onclick="handanlist('+type+','+dealtype+','+(data.page+1)+')">下一页</span>&nbsp;';
                        }else{
                            str += '<span>下一页</span>&nbsp;';
                        }
                        str += '<b style="margin-right: 5px;">跳转</b>';
                        str += '<input type="text" style="width:40px;height:28px;text-indent: 5px;" id="goPage"/>';
                        str += '<b style="margin:0 5px 0 5px;">页</b>';
                        str += '<span onclick="goPage('+type+','+dealtype+')" style="background-color:#3b9ce0;width:40px;margin-right: 5px;" >go</span>';
                        str += '共<b>'+data.allpage+'</b>'+'页&nbsp;';
                        str += '</div>';
                    }    
                }else{
                    str  = '<div style="text-align:center;padding:10px;">暂无数据</div>';
                }
                $('.j_handannav').html(str);
            }
        });
    }
// goPage方法
function goPage(type,dealtype){
    var page = parseInt($("#goPage").val()) ? parseInt($("#goPage").val()) :1;
    handanlist(type,dealtype,page);
}
//时间戳转换函数    
function UnixToDate(unixTime, isFull, timeZone,type) {
        if (typeof (timeZone) == 'number')
        {
            unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
        }
        var time = new Date(unixTime * 1000);
        var ymdhis = "";
        if(type){
            ymdhis += time.getFullYear() + "-";
            ymdhis += (time.getMonth()+1)>9?(time.getMonth()+1)+'-':'0'+(time.getMonth()+1) + "-";
            ymdhis += time.getDate()>9?time.getDate():'0'+time.getDate();
        }
        if (isFull === true)
        {

            ymdhis += " " + time.getHours()>9?time.getHours()+ ":":'0'+time.getHours() + ":";
            ymdhis += time.getMinutes()>9?time.getMinutes()+ ":":'0'+time.getMinutes() + ":";
            ymdhis += time.getSeconds()>9?time.getSeconds():'0'+time.getSeconds();
        }
        return ymdhis;
    }    
